package flex.cc.system.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import flex.cc.base.dto.LoginAuthDto;
import flex.cc.core.support.BaseController;
import flex.cc.system.entity.DictTypeEntity;
import flex.cc.system.service.DictTypeService;
import flex.cc.system.vo.DictTypeVo;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;



/**
 * 
 *
 * @author lmq
 * @email limengqi@sinosoft.com.cn
 * @date 2020-09-18 16:04:04
 */
@RestController
@RequestMapping("/uac/dicttype")
public class DictTypeController extends BaseController {
    @Autowired
    private DictTypeService dictTypeService;

    /**
     * 查询数据字典主类型
     * @return the wrapper
     */
    @PostMapping(value = "/searchAllType")
    @ApiOperation(httpMethod = "POST", value = "查询数据字典主类型")
    public Wrapper<IPage<DictTypeEntity>> searchAllType(@RequestBody DictTypeEntity dictTypeEntity) {
    	IPage<DictTypeEntity> result = dictTypeService.searchAllType(dictTypeEntity);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 查询数据字典主类型-打开编辑type页面
     * @return the wrapper
     */
    @GetMapping(value = "/searchDictTypeById/{id}")
    @ApiOperation(httpMethod = "GET", value = "查询数据字典主类型")
    public Wrapper<DictTypeEntity> searchDictTypeById(@PathVariable(value = "id") Long id) {
    	DictTypeEntity result = dictTypeService.getById(id);
        return WrapMapper.ok(result);
    }
    
    /**
     * 保存或修改数据字典主类型
     * @return the wrapper
     */
    @PostMapping(value = "/saveOrUpdateDictType")
    @ApiOperation(httpMethod = "POST", value = "保存或修改数据字典主类型")
    public Wrapper<String> saveOrUpdateDictType(@RequestBody DictTypeVo vo) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	String result = dictTypeService.saveOrUpdateDictType(vo,loginAuthDto);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 逻辑删除数据字典主类型 页面先调用searchDictTypeById方法查询该type没有下级时才可以删除
     * @return the wrapper
     */
    @GetMapping(value = "/deleteDictTypeById/{id}")
    @ApiOperation(httpMethod = "GET", value = "逻辑删除数据字典主类型")
    public Wrapper<Boolean> deleteDictTypeById(@PathVariable(value = "id") Long id) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	boolean result = dictTypeService.deleteDictTypeById(id,loginAuthDto);
    	return WrapMapper.ok(result);
    }

}
